<?php
class Frontend_Table_Category extends Custom_Model_Table_Abstract
{
    protected $_name            = 'category';
    protected $_rowClass        = 'Frontend_Table_Row_Category';
    
    protected $_referenceMap = array(
        'SubCategory' => array(
            'columns'       => 'parent_id',
            'refTableClass' => 'Frontend_Table_Category',
            'refColumns'    => 'id',
        )
    );

    public function findAll()
    {
        return $this->fetchAll();
    }


    public function findById($id)
    {
        return $this->find((int)$id)->current();
    }

    public function findByParentId($id)
    {
        $select = $this->select()
                       ->where('parent_id = ?',(int)$id)
                       ->order('sort_order');

        return $this->fetchAll($select);
    }

    public function findParentById($id)
    {
        $row = $this->findById((int)$id);
        return $this->find($row->parent_id)->current();
    }
}
?>
